package com.plian.system.controller.hr.recruitment;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.dto.hr.recruitment.PartTimeManagementDTO;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ObjResult;
import com.plian.system.service.hr.recruitment.IPartTimeManagementService;
import com.plian.system.vo.report.ReportReturnVO;
import com.plian.system.wrapper.hr.recruitment.PartTimeManagementWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 *  控制器
 *
 * @author BladeX
 * @since 2019-12-02
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("api/parttimemanagement")
public class PartTimeManagementController extends BaseController {

	private IPartTimeManagementService partTimeManagementService;

	private PartTimeManagementWrapper partTimeManagementWrapper;


//    /**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public ObjResult detail(@Valid @RequestBody PartTimeManagement partTimeManagement) {
//		PartTimeManagement detail = partTimeManagementService.getOne(Condition.getQueryWrapper(partTimeManagement));
//		PartTimeManagementVO partTimeManagementVO = partTimeManagementWrapper.entityToVO(detail);
//		return partTimeManagementService.getDetailObj(partTimeManagementVO);
//	}
//
//	/**
//	* 分页
//	*/
//	@PostMapping("/list")
//	public ListResult<PartTimeManagementVO> list(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//		List<SearchEntity> entityList = query.getSearch();
//		QueryWrapper<PartTimeManagement> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new PartTimeManagement()), entityList
//		);
//		TokenSearch<PartTimeManagement> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//		IPage<PartTimeManagement> pages = partTimeManagementService.page(Condition.getPage(query), queryWrapper);
//		List<PartTimeManagementVO> partTimeManagementVOS = partTimeManagementWrapper.entityToVO(pages.getRecords());
//		ListResult<PartTimeManagementVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(partTimeManagementVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//	/**
//	* 新增或修改
//	*/
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody PartTimeManagement partTimeManagement) {
//		String checkMessage = partTimeManagementService.checkSubmit(partTimeManagement);
//		if (StringUtil.isNotBlank(checkMessage)){
//			return new R(CustomCode.builder().message(checkMessage).code(1999).success(false).build());
//		}
//		return partTimeManagementService.submit(partTimeManagement)
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	 * 变更
//	 */
//	@PostMapping("/change")
//	public R change(@Valid @RequestBody PartTimeManagement partTimeManagement) {
//		return partTimeManagementService.change(partTimeManagement)
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	* 删除
//	*/
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//		List<String> ids = (List<String>)pd.get("ids");
//		return partTimeManagementService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//    /**
//     * 弃审
//     */
//    @PostMapping("/cancel")
//    public R cancel(@RequestParam Long id) {
//        return partTimeManagementService.cancel(id)
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	 * 打印预览
//	 */
//	@GetMapping("/buildpdf/{id},{type}")
//	@PassToken
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id, @PathVariable Integer type) {
//		return FileTools.exportPdf(partTimeManagementService.buildpdf(id,type));
//	}
//
//	/**
//	 * 导入
//	 */
//	@PostMapping("/import")
//	public ObjResult excelImport(@RequestParam("file") MultipartFile multipartFile){
//		ImportResult importResult = partTimeManagementService.importExcel(multipartFile);
//		if(importResult.isSuccess()){
//			return new ObjResult(CommonCode.SUCCESS);
//		}else{
//			return new ObjResult(CustomCode.builder().message(importResult.getMsg()).code(1999).success(false).build());
//		}
//	} TODO DEL

	@PostMapping("/partTimeDetail")
	public ObjResult  partTimeDetail(@RequestBody PartTimeManagementDTO partTimeManagementDTO) {
		ObjResult objResult;
		try {
			ReportReturnVO reportReturnVO = partTimeManagementService.selectPartTimeManagementMain(partTimeManagementDTO);
			objResult = new ObjResult(CommonCode.SUCCESS);
			if (Optional.ofNullable(reportReturnVO).isPresent()){
				PageData pd = new PageData();
				pd.put("grids", reportReturnVO.getGrids());
				objResult.setPageData(pd);
			}
		}catch (Exception e) {
			log.error(ExceptionUtils.getFullStackTrace(e));
			objResult = new ObjResult(CommonCode.ERROR);
			return objResult;
		}
		return objResult;
	}

}
